package org.abettor.angleworm.router.impl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.abettor.angleworm.router.Tunnel;
import org.abettor.angleworm.router.TunnelEventListener;

/**
 * @see org.abettor.angleworm.router.Tunnel
 * @author <a href="http://www.abettor.org/" target="_blank">abettor</a>
 *
 */
public class TunnelImpl implements Tunnel
{
	private List<TunnelEventListener> listeners = Collections.synchronizedList(new ArrayList<TunnelEventListener>());

	@Override
	public void addListener(TunnelEventListener listener)
	{
		listeners.add(listener);
	}

	@Override
	public void removeAllListeners()
	{
		listeners.clear();
	}

	@Override
	public void removeListener(TunnelEventListener listener)
	{
		listeners.remove(listener);
	}

	@Override
	public void close() throws IOException
	{
		//TODO	关闭本通信通道，并清理相关信息，这里有不少东西要做。
		removeAllListeners();
	}
}
